<?php
class Server {
  public static function submit_obj($orm, $sys, $inst, $is_iframe) {
    $req = json_decode(Utils::get_param('req', '[]'));
    
    if ($req->name == '') {
      echo 'Name is empty';
      return;
    }
    
    if ($req->formal_name == '') {
      echo 'Formal Name is empty';
      return;
    }
    
    if (isset($req->id) && $req->id != 0) {
      $orm->update('pb_colg_program', $req);
    } else {
      $orm->add('pb_colg_program', $req);
      $req->id = $orm->last_id();
    }
    
    if (isset($req->__pg)) {
      $opts = new stdClass();
      $opts->cd = 't.type = :v1';
      $opts->cdv = array(':v1' => PT_LANGUAGE);
      $req->__objs = $orm->get('pb_colg_program', 't.name', 'ASC', $req->__pg, SIZE, $opts);
    }
    
    echo json_encode($req);
  }
  
  public static function get_obj($orm, $sys, $inst, $is_iframe) {
    $req = json_decode(Utils::get_param('req', '[]'));
    
    $opts = new stdClass();
    $opts->cd = 't.id = :v1';
    $opts->cdv = array(':v1' => $req->id);
    $res = $orm->get('pb_colg_program', NULL, NULL, NULL, NULL, $opts)->d;
    
    echo json_encode($res);
  }
}
?>